# -*- ecoding: utf-8 -*-
# @ModuleName: mysql_db
# @Author: wangwei 
# @Time: 2023/10/20 11:15
import pymysql


class MysqlUtil:

    def __init__(self,host="localhost",user="root",password="123456",port=3306,db=None):
        self.conn=pymysql.Connect(host=host,user=user,password=password,port=port,db=db,cursorclass=pymysql.cursors.DictCursor)

    def select(self,sql):
        cursor=self.conn.cursor()
        cursor.execute(sql)
        self.conn.commit()
        content=cursor.fetchall()
        cursor.close()
        return content


    def update(self, sql):
        cursor = self.conn.cursor()
        cursor.execute(sql)
        self.conn.commit()
        print(cursor.rowcount)
        cursor.close()

    def close(self):
        self.conn.close()

if __name__ == '__main__':
    print(MysqlUtil().select('select * from student.student limit 1') )
    print(MysqlUtil().update("update student.student set Sname='ruinika' where id='20'"))




